﻿using System;
using System.Collections.Generic;
using System.Windows.Media;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Convertor.Interface;
using Wpf.CommonTools.SystemExtension;
using System.Collections.ObjectModel;

namespace Convertor
{
    class PluginInstallConverter : IMultiValueConverter
    {
        /*
        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            IPluginItem item = value as IPluginItem;
            if (parameter.Equals("Content"))
            {
                if (item == null)
                {
                    return UILanguage.FindResource("Install");
                }
                else if (Config.GlobalConfig.DisabledPlugin.Contains(item.Path))
                {
                    return UILanguage.FindResource("Install");
                }
                else
                {
                    return UILanguage.FindResource("UnInstall");
                }
            }
            else if (parameter.Equals("Foreground"))
            {
                if (item == null)
                {
                    return Brushes.Black;
                }
                if (Config.GlobalConfig.DisabledPlugin.Contains(item.Path))
                    return Brushes.Gray;
                else
                    return Brushes.Black;
            }
            else
            {
                return item != null;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
        */

        #region IMultiValueConverter 成员

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            IPluginItem item = values[0] as IPluginItem;
            Collection<string> disablePluginList = values[1] as Collection<string>;
            if (parameter.Equals("Content"))
            {
                if (item == null)
                {
                    return UILanguage.FindResource("Install");
                }
                else if (disablePluginList.Contains(item.Path))
                {
                    return UILanguage.FindResource("Install");
                }
                else
                {
                    return UILanguage.FindResource("UnInstall");
                }
            }
            else if (parameter.Equals("Foreground"))
            {
                if (item == null)
                {
                    return Brushes.Black;
                }
                if (disablePluginList.Contains(item.Path))
                    return Brushes.Gray;
                else
                    return Brushes.Black;
            }
            else
            {
                return item != null;
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
